package com.ai.tools;

import com.ai.domain.vo.ChatCourseVO;
import com.ai.domain.vo.CourseVo;
import com.ai.domain.vo.PurchasedCourseVo;
import com.ai.feign.CourseFeignClient;

import com.common.context.UserContextHolder;
import jakarta.annotation.Resource;
import org.springframework.ai.chat.model.ToolContext;
import org.springframework.ai.tool.annotation.Tool;
import org.springframework.ai.tool.annotation.ToolParam;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CourseToolService {

    @Resource
    CourseFeignClient courseFeignClient;

    @Tool(name = "queryCourseList", description = "查询指定的课程信息")
    public List<ChatCourseVO> queryCourseList(ToolContext toolContext,
                                              @ToolParam(description = "课程标签", required = false) String label,
                                              @ToolParam(description = "课程名称", required = false) String teacherName,
                                              @ToolParam(description = "课程分类", required = false) String categoryName) {

        return List.of();
    }

    @Tool(name = "queryCourseListByUserName", description = "查询用户发布的课程")
    public List<CourseVo> queryCourseListByUserName(ToolContext toolContext,
                                                    @ToolParam(description = "用户名") String username) {
        return courseFeignClient.getCourseListPublishByUsername(username).getData();
    }

    @Tool(name = "searchPurchasedCourses", description = "查询当前用户已购买的课程")
    public List<String> searchPurchasedCourses(ToolContext toolContext) {
        List<PurchasedCourseVo> userCourseList = courseFeignClient.getCourseListBuyByUserId(UserContextHolder.getContext().getUsersId()).getData();
        return userCourseList.stream()
                .map(PurchasedCourseVo::getName)
                .toList();
    }
}
